home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
COMMAIZE.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
1KB
|
54 lines
############################################################################
#
# File: commaize.icn
#
# Subject: Procedures to add commas to real or integers
#
# Author: Ralph Griswold and Richard L. Goerwitz
#
# Date: September 28, 1992
#
###########################################################################
#
# Version: 1.1
#
###########################################################################
#
# Comma-izes reals or integers (e.g. -1040.39 -> "-1,040.39").
#
############################################################################
#
# Links: none
#
############################################################################
procedure commaize(s)
local s2, sign
# Don't bother if s is already comma-ized.
if type(s) == "string" then find(",", s) & fail
# Take sign. Save chars after the decimal point (if present).
if s := abs(0 > s)
then sign := "-" else sign := ""
s ? {
s := tab(find(".")) & ="." &
not pos(0) & s2 := "." || integer(tab(0))
}
/s2 := ""
integer(s) ? {
tab(0)
while s2 := "," || move(-3) || s2
if pos(1)
then s2 ?:= (move(1), tab(0))
else s2 := tab(1) || s2
}
return sign || s2
end